package com.flyme.module.base.provider.controller;

import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.common.core.utils.ObjectUtils;
import com.flyme.core.base.supper.controller.BaseController;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.module.base.client.api.SysSharelogRemoteService;
import com.flyme.module.base.client.entity.SysSharelog;
import com.flyme.module.base.provider.service.SysSharelogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RestController;

/**
 * 分享记录管理
 * @author zyh
 * @date 2020-8-18
 */
@Api(tags = "分享记录")
@RestController
public class SysSharelogController extends BaseController<SysSharelogService, SysSharelog> implements SysSharelogRemoteService {

    /**
     * 分享记录列表
     *
     * @return
     */
    @ApiOperation(value = "分享记录分页列表", notes = "分享记录分页列表")
    @Override
    public ResultBody list(@ModelAttribute(value = "pagerInfo") PagerInfo pagerInfo, String profitUser) {
        CriteriaQuery cq = new CriteriaQuery<EntityMap>(pagerInfo);
        cq.addSql("s.*, user.userName profitUser");
        cq.addSql("(SELECT su.userName FROM sys_user su WHERE id = s.userId) invitees");
        cq.createAlias("user", "user");
        if(ObjectUtils.isNotEmpty(profitUser)){
            cq.like("user.userName", profitUser);
        }
        PqGrid pqGrid = bizService.pageList(cq);
        return ResultBody.success(pqGrid);
    }

}
